package edu.washington.cs.gitanaly;

import org.eclipse.jgit.treewalk.TreeWalk;
import org.eclipse.jgit.treewalk.filter.TreeFilter;

public class AllDiffFilter extends TreeFilter {

	public AllDiffFilter() {
		
	}
	
	@Override
	public boolean include(TreeWalk treeWalk) {
		int n = treeWalk.getTreeCount();

		if (n == 1) {
			return true;
		}

		int m = treeWalk.getRawMode(0);

		for (int i = 1; i < n; ++i) {
			if (treeWalk.getRawMode(i) == m && treeWalk.idEqual(0, i)) {
				return false;
			}
		}

		return true;
	}

	@Override
	public TreeFilter clone() {
		return this;
	}

	@Override
	public boolean shouldBeRecursive() {
		return true;
	}
}
